﻿import com.dmotiko.general.*
import com.dmotiko.ada.*
import mx.transitions.*;
import mx.transitions.easing.*;

class CelebrityButton
extends BaseClip {
	
	private var txtLabel:TextField;
	private var mcStroke:MovieClip;
	private var mcStrokeMask:MovieClip;
	private var tStroke:Tween;
	private var tAlpha:Tween;
	private var bActive:Boolean;
	
	private function initClip():Void {
		this._alpha = 70;
		mcStroke._visible = false;
		txtLabel.autoSize = "left";
	}
	
	public function onRollOver():Void {
		if (tAlpha) tAlpha.stop();
		tAlpha = new Tween( this, "_alpha", Regular.easeOut, this._alpha, 100, 0.5, true);
		if (tStroke) tStroke.stop();
		tStroke = new Tween( mcStrokeMask, "_x", Regular.easeOut, mcStrokeMask._x, mcStrokeMask.initX, 0.5, true);
	}
	
	public function onRollOut():Void {
		if (bActive) return;
		if (tAlpha) tAlpha.stop();
		tAlpha = new Tween( this, "_alpha", Regular.easeOut, this._alpha, 70, 0.5, true);
		if (tStroke) tStroke.stop();
		tStroke = new Tween( mcStrokeMask, "_x", Regular.easeOut, mcStrokeMask._x, mcStrokeMask.initX - mcStroke._width, 0.5, true);
	}
	
	public function onRelease():Void {
		this.dispatchEvent( { target: this, type: BaseClipEvent.CHANGED, data: this.data } );
	}
	
	public function setActive(bActive):Void {
		if (bActive == this.bActive) return;
		this.bActive = bActive;
		onRollOut();
	}
		
	private function refreshData():Void {
		//trace("CelebrityButton | refreshData= " + data.description);
		txtLabel.text = this.data.description;
		mcStroke._width = txtLabel._width;
		mcStrokeMask = mcStroke.duplicateMovieClip("mcStrokeMask", this.getNextHighestDepth(), mcStroke);
		mcStrokeMask.initX = mcStrokeMask._x;
		mcStrokeMask._x = mcStroke._x - mcStroke._width;
		mcStroke.setMask(mcStrokeMask);
		mcStroke._visible = true;
	}
	
}